package com.tiankun.eurekauserinfo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created with IntelliJ IDEA
 * User: bear
 * Date: 2020/11/13
 * Description
 * Version: V1.0
 */
public class RandomNumber {
    public static String randomNumber() {
        //订单号生成的时间取决下单时间
        Date date = new Date();
        //转换时间格式，变成string字符串
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String sDate = format.format(date);
        String result = "";
        Random random = new Random();
        //为了防止大量并发的情况可能出现订单号重复，加上六位随机数
        for (int i = 0; i < 6; i++) {
            result += random.nextInt(10);
        }
        return sDate + result;
    }
}
